package com.jjyu.controller;

import com.jjyu.entity.Feedback;
import com.jjyu.service.FeedbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/feedback")
public class FeedbackController {

    @Autowired
    private FeedbackService feedbackService;

    @PostMapping("/recommendations")
    public ResponseEntity<String> submitFeedback(@RequestBody Feedback feedback) {
        try {
            boolean result = feedbackService.submitFeedback(feedback);
            if (result) {
                return ResponseEntity.ok("反馈提交成功");
            } else {
                return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("反馈提交失败");
            }
        } catch (Exception e) {
            // 记录日志
            e.printStackTrace();
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("服务器错误");
        }
    }
}